//
//  CCTabBar.m
//  Baisibudejie
//
//  Created by yu hu on 2017/3/20.
//  Copyright © 2017年 yu hu. All rights reserved.
//

#import "CCTabBar.h"

@implementation CCTabBar
{
    UIButton *_publishBtn;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        UIButton *publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateSelected];
        [publishButton addTarget:self action:@selector(publishClick) forControlEvents:UIControlEventTouchUpInside];
        _publishBtn = publishButton;
        publishButton.size = publishButton.currentBackgroundImage.size;
        [self addSubview:publishButton];
    }
    
    return self;
}


#pragma mark --- ➕点击
- (void)publishClick
{
    XMGLogFunc;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    // 设置发布按钮的frame
    _publishBtn.bounds = CGRectMake(0, 0, _publishBtn.currentBackgroundImage.size.width, _publishBtn.currentBackgroundImage.size.height);
    _publishBtn.center = CGPointMake(self.width * 0.5, self.height * 0.5);
    
    //设置其他UITabBarButton的frame
    CGFloat buttonY = 0;
    CGFloat buttonW = self.width / 5;
    CGFloat buttonH = self.height;
    NSInteger index = 0;
    for (UIView *button in self.subviews) {
         if (![button isKindOfClass:NSClassFromString(@"UITabBarButton")])continue;
        button.frame = CGRectMake(buttonW * (index>1?index+1 : index), buttonY, buttonW, buttonH);
          index++;
    }
}
@end
